<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>添加常用联系人</title>
    <link rel="stylesheet" href="../../../css/aui.css" />
</head>

<body style="cursor: pointer;">
    <div class="aui-content aui-margin-b-15">
        <ul class="aui-list aui-form-list">
            <!--<li class="aui-list-header">带有图标的表单</li>-->
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label-icon">
                        <i class="aui-iconfont aui-icon-my"></i>
                    </div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请输入常用联系人姓名" class="name">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label-icon">
                        <i class="aui-iconfont aui-icon-phone"></i>
                    </div>
                    <div class="aui-list-item-input">
                        <input type="number" placeholder="请输入常用联系人手机号码" class="phone">
                    </div>
                </div>
            </li>
        </ul>
        <div class="aui-btn aui-btn-success aui-btn-block aui-btn-sm submit" style="margin:.7rem auto;width:50%;background:#3cb0d6;" onclick="contact_add()">提交</div>
    </div>
</body>
<script type="text/javascript" src="../../../script/aui/api.js"></script>
<script type="text/javascript" src="../../../script/aui/aui-toast.js"></script>
<script type="text/javascript" src="../../../script/extend/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="../../../script/config.js"></script>
<script type="text/javascript" src="../../../script/common.js"></script>

<script>
    apiready = function() {
        api.parseTapmode();

    }

    function contact_add() {
        var toast = new auiToast({});
        var serverUrl = Config.common.addContact,
            name = $('.name').val(),
            mobile = $('.phone').val();
        if (!$.trim(name)) {
            toast.fail({
                title: '姓名不能为空',
                duration: 2000
            });
            return false;
        }
        if (!isPhoneNo(mobile)) {
            toast.fail({
                title: '手机号码格式不正确',
                duration: 2000
            });
            return false;
        }
        var data = {
            contact_name: $('.name').val(),
            contact_mobile: $('.phone').val()
        };
        ajax({
            url: serverUrl,
            data: data
        }, function(ret) {
            if (ret.code == 1) {
                toast.success({
                    title: '添加成功',
                    duration: 2000
                });
                var add_type = $api.getStorage("add_contact_type");
                if (add_type === "hotel") {
                    setTimeout(function() {
                        openWin('contact_list', '../../trip/hotel/contact_list_win.html');
                    }, 1000);
                }
                //跳转至常用联系人列表
                setTimeout(function() {
                    api.closeToWin({
                        name: "index_win"
                    });
                    api.sendEvent({
                        name: 'submitReload',
                        extra: {
                            on : 1
                        }
                    });
                }, 2000);
            }
        });
    }

    function isPhoneNo(phone) {
        var pattern = /^1[34578]\d{9}$/;
        return pattern.test(phone);
    }
</script>

</html>
